package cn.wsalix.admin.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import cn.anlaser.entity.ParentEntity;
import cn.wsalix.admin.status.RoleEnum;

@Entity
@Table(name = "ADMIN_ROLE")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Data
@EqualsAndHashCode(callSuper = false)
@ToString(exclude = { "menus" })
public class SysRole extends ParentEntity<SysRole> {
	
	public SysRole() {
	}
	public SysRole(String code) {
		this.code = code;
	}
	public SysRole(String code, String name) {
		this.code = code;
		this.name = name;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -7118434573360282160L;
	@Column(name = "NAME")
	private String name;
	@Column(name = "CODE")
	protected String code;

/*	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
	private Set<UserRole> userRole;*/
	@Transient
	private String selected;
	private RoleEnum status;

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "ROLE_MENU", joinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "MENU_ID", referencedColumnName = "ID") })
	private List<SysMenu> menus;

}
